// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env:'yun-2go2p8wr70c54da4'
})

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const db = cloud.database()
  const collectionDirection = db.collection('subben_income')
  const directions = await collectionDirection.aggregate()
      .project({
        _id:0,
      money:1
      }).end()
      let array = directions.list
      console.log('arr',array)
      let im =0
      let n = 0
      for(let i = 0; i <array.length; i++){
        n = Number(array[i].money)
        im += n
      }
      console.log('总收入:',im) // 总收入

  return {
   im
  }
}